package com.atguigu.gulimall.order.leetcode;

/**
 * @Description
 * @Author lhj
 * @Date 2024/5/18 10:02
 */
public class 移除元素_27 {

    public static void main(String[] args) {
        System.out.println(removeElement(new int[]{1}, 1));
    }
    
    public static int removeElement(int[] nums, int val) {
        if (nums.length == 1) {
            Integer temp = null;
            nums[0] = temp;
        }
        int left = 0, right = nums.length - 1;
        while (left < right) {
            if (nums[left] == val) {
                if (nums[left] == nums[right]) {
                    right --;
                }else {
                    int temp = nums[right];
                    nums[right] = nums[left];
                    nums[left] = temp;
                    right --;
                    left ++;
                }
            }else {
                left ++;
            }
        }
        return left + 1;
    }
}
